package com.sai.open.mrp;
import android.widget.BaseAdapter;
import java.util.List;
import android.view.LayoutInflater;
import android.content.Context;
import java.util.ArrayList;
import android.view.View;
import android.view.ViewGroup;
import com.sai.open.sky.R;
import android.widget.TextView;
import android.widget.Button;
import android.widget.ImageView;
import com.sai.open.BaseActivity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import com.sai.tool.PixelDrawable;

public class ListAdapter extends BaseAdapter
{
	public List<MrpDef> list;
	private LayoutInflater inflater;

	private Context mContext;

	public ListAdapter(Context mContext)
	{
        this.mContext = mContext;
        inflater = LayoutInflater.from(mContext);
        list = new ArrayList<MrpDef>();
    }

	public void setListData(List<MrpDef> data)
	{
		this.list = data;
	}

	@Override
	public int getCount()
	{
		// TODO: Implement this method
		return list.size();
	}

	@Override
	public Object getItem(int p1)
	{
		// TODO: Implement this method
		return list.get(p1);
	}

	@Override
	public long getItemId(int p1)
	{
		// TODO: Implement this method
		return p1;
	}


	@Override
	public View getView(int position, View convertView, ViewGroup p3)
	{
		// TODO: Implement this method
		final ViewHolder viewHolder;
        final MrpDef data = list.get(position);
        if (convertView == null)
		{
            //设置列表布局
            convertView = inflater.inflate(R.layout.pages_select_item, null);
            viewHolder = new ViewHolder();
            //获取布局中的控件
            viewHolder.img2 = convertView.findViewById(R.id.p_select_img);
            viewHolder.name =  convertView.findViewById(R.id.p_select_name);
            viewHolder.file = convertView.findViewById(R.id.p_select_file);
            convertView.setTag(viewHolder);
        }
		else
		{
            viewHolder = (ViewHolder) convertView.getTag();
        }

		Bitmap bmp = BaseActivity.getImageFromAssetsFile("imgs/"+data.filename+".png", mContext);
		BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bmp); 
		viewHolder.img2.setImageDrawable(new PixelDrawable(drawable)); 
        viewHolder.name.setText(data.showname);
        viewHolder.file.setText(data.filename);
		
		((BaseActivity)mContext).changeFont((ViewGroup)convertView);
		return convertView;
	}



	class ViewHolder
	{
        private ImageView img2;
        private TextView name, file; 
    }

}

